//
//  WonThePraiseCell.m
//  OnionHome
//
//  Created by fengjie on 2019/9/14.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "WonThePraiseCell.h"

@interface WonThePraiseCell ()
/**左边图标*/
@property (nonatomic,strong)UIImageView*leftImage;
/**名称*/
@property (nonatomic,strong)UILabel*nameLabel;
/**时间*/
@property (nonatomic,strong)UILabel*timerLabel;
/**右边r图片*/
@property (nonatomic,strong)UIImageView*rightImage;
@end

@implementation WonThePraiseCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)createUI{
//    self.backgroundColor = RGB(236, 239, 243);
    
    [self addSubview:self.leftImage];
    [self addSubview:self.nameLabel];
    [self addSubview:self.timerLabel];
    [self addSubview:self.rightImage];
    
    [self.leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.bottom.mas_equalTo(-16);
        make.width.height.mas_equalTo(64);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.leftImage.mas_right).offset(10);
        make.top.mas_equalTo(self.leftImage.mas_top).offset(8);
    }];
    [self.timerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.leftImage.mas_right).offset(10);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(9);
    }];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.leftImage);
        make.right.mas_equalTo(-16);
        make.width.height.mas_equalTo(80);
    }];
}
-(void)setModel:(WonThePraiseModel *)model{
    _model = model;
    self.leftImage.image = IMAGE_NAMED(model.userIcon);
    if (model.isCollection) {
//        self.nameLabel.text = [NSString stringWithFormat:@"%@ 收藏了",model.userName];
        self.nameLabel.attributedText = [self createNameTitle:model.userName Title:@" 收藏了"];
    }else{
//        self.nameLabel.text = [NSString stringWithFormat:@"%@ 赞了你",model.userName];
        self.nameLabel.attributedText = [self createNameTitle:model.userName Title:@" 赞了你"];

    }
    self.timerLabel.text = model.dataTime;
    self.rightImage.image = IMAGE_NAMED(model.rightImage);
    
}
-(NSMutableAttributedString *)createNameTitle:(NSString *)name Title:(NSString *)title{
    
    
    
    NSMutableAttributedString * string = [NSMutableAttributedString makeAttributeString:name Attribute:^(NSMutableDictionary * _Nonnull attributes) {
        attributes.Color(UIColorFromRGB(0x273323));
        [attributes setValue:PingFangSC_Medium(16) forKey:NSFontAttributeName];
    }];
    
    [string makeAttributeStringAdd:title Attribute:^(NSMutableDictionary * _Nonnull attributes) {
        attributes.Color(UIColorFromRGB(0x273323));
        [attributes setValue:SYSTEMFONT(14) forKey:NSFontAttributeName];

    }];
    
    return string;
}
#pragma mark --懒加载

-(UIImageView*)leftImage{
    if(!_leftImage){
        _leftImage=[UIImageView new];
        _leftImage.layer.cornerRadius = 32;
        _leftImage.layer.masksToBounds = YES;
        _leftImage.image = IMAGE_NAMED(@"userIconDefut");
    }
    return _leftImage;
}
-(UILabel*)nameLabel{
    if(!_nameLabel){
        _nameLabel=[UILabel new];
        _nameLabel.textColor = UIColorFromRGB(0x273323);
        _nameLabel.font = BOLDSYSTEMFONT(16);
        _nameLabel.text = @"大鲨鱼";
    }
    return _nameLabel;
}
-(UILabel*)timerLabel{
    if(!_timerLabel){
        _timerLabel=[UILabel new];
        _timerLabel.textColor = UIColorFromRGB(0x959E97);
        _timerLabel.font = SYSTEMFONT(12);
        _timerLabel.text = @"2018-06-09";
    }
    return _timerLabel;
}

-(UIImageView*)rightImage{
    if(!_rightImage){
        _rightImage=[UIImageView new];
        _rightImage.image = IMAGE_NAMED(@"dynamicDefut");

    }
    return _rightImage;
}
@end
